<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="thx" uri="/thx-tags"%>
<style>
.form-horizontal .form-group {
	margin-right: 0px;
	margin-left: 0px;
}
</style>

<!-- Main content -->
<section class="content">
	<div class="page-header">
	  <h1 class="text-center">${view.information.infoTitle}</h1>
	</div>
	<div id="commons">
		<div class="container-fluid">
			<div class="row">
				<div class="col-sm-11">
					<p class="text-center">
					发布人:${view.information.createUser} 时间:${view.information.createTime} 浏览次数:${view.viewCount} 
					<c:if test="${view.information.canComment=='1'}">
					<span class="label label-info">
					<i class="fa fa-commenting"></i>${view.commentsNum}
					</span>
					</c:if>
					</p>
				</div>
				<div class="col-sm-1">
					<p class="text-center">
					<button type="button" 
							title="栏目" 
							data-toggle="tooltip"
							data-placement="bottom"
							class="information-columngoBut" 
							data-id="${belongInfoColumn.columnId}">
							<i class="fa fa-list"></i>
					</button>
					</p>
				</div>
			</div>
			<div class="row-fluid">
				<div class="span12">
					${view.information.infoContent}
				</div>				
			</div>
			<!-- 开始投票显示区域 -->
			<c:if test="${view.information.canVote=='1'}">
			<div class="box-body no-padding">
				<div class="row">
					<div class="col-sm-12">
						<table class="table table-bordered">
							<tr>
	  							<th>参与人数<br/>${view.voteJoinNum}</th>
	  							<td style="text-align: left;">
	  							<b>${view.information.infoTitle}</b><br/>
	  							投票模式
	  							<c:if test="${view.information.voteMode=='0'}"><b>实名模式</b>|所有人都可以看到投票结果和投票人姓名</c:if>
	  							<c:if test="${view.information.voteMode=='1'}"><b>匿名模式</b>|所有人都只能看到投票结果而不能看到投票人姓名</c:if>
	  							<c:if test="${view.information.voteMode=='2'}"><b>管理员模式</b>|只有管理员才能查看到投票结果和投票人姓名</c:if>
	  							|
	  							<c:if test="${view.information.voteStatus=='1'}">投票正在进行中</c:if>
	                            <c:if test="${view.information.voteStatus=='0'}">投票已结束</c:if>
	                            <c:if test="${empty view.information.voteStatus}">投票未开始</c:if>
	  							</td>
							</tr>
						</table>
						<form id="vote-form" class="form-horizontal" data-toggle="validator" role="form" method="post">
						<s:token></s:token>
						<input type="hidden" name="pid" value="${view.information.infoId}"/>
						<table class="table table-bordered">
							<c:forEach items="${view.infoVoteItemLog}" var="commenlog">
								<tr>
									<td style="text-align: left;">
									<c:if test="${view.information.itemForm=='0'}"><input type="radio" name="voteItemIds" id="voteItemIds" value="${commenlog.infoVoteItem.voteItemId}" ></c:if>
									<c:if test="${view.information.itemForm=='1'}"><input type="checkbox" name="voteItemIds" id="voteItemIds" value="${commenlog.infoVoteItem.voteItemId}" ></c:if>
									${commenlog.infoVoteItem.optionName}
									</td>
									<td><i class="fa fa-bar-chart">${commenlog.voteTotal}</i></td>
								</tr>
							</c:forEach>
						</table>
						</form>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<!--底部操作区-->
				<div class="handlePanel">
					<c:if test="${perIfVote==true}">
						<span class="fa fa-bar-chart"></span>
						<span class="text">已投票</span>
					</c:if>
					<c:if test="${perIfVote==false}">
					<a title="投票" 
						class="a-btn information-joinVoteBut"
						data-id="${view.information.infoId}"> 
						<span class="fa fa-bar-chart"></span>
						<span class="text">投票</span>
					</a>
					</c:if>	
				</div>
			</div>
			</c:if>
			<!-- 结束投票显示区域 -->	
			<!-- 开始评论显示区域 -->
			<c:if test="${view.information.canComment=='1'}">
			<div class="row-fluid">
			 <!-- Chat box -->
              <div class="box box-success">
                <div class="box-header">
                  <i class="fa fa-commenting"></i>
                  <h3 class="box-title">评论</h3>
                  <div class="box-tools pull-right" data-toggle="tooltip" title="Status">
                    <div class="btn-group" data-toggle="btn-toggle" >
                    </div>
                  </div>
                </div>
                <div class="box-body chat" id="chat-box">
                <c:forEach items="${view.infoCommentLog}" var="commenlog">
					<!-- chat item -->
                  <div class="item">
                    <img src="${pageContext.request.contextPath}/images/user.jpg" alt="user image" class="online">
                    <p class="message">
                      <a href="#" class="name">
                        <small class="text-muted pull-right"><i class="fa fa-clock-o"></i> ${commenlog.commentDate}</small>
                        ${commenlog.perName}(${commenlog.deptName})
                      </a>
                      ${commenlog.content}
                    </p>
                  </div><!-- /.item -->                
                </c:forEach>
                </div><!-- /.chat -->
                <div class="box-body chat" id="chat-box">
					<div class="pagePanel">
			           	 <thx:pages pageNo="page.curPage" total="page.totalPage"  theme="number">
							<s:param name="id" value="id"></s:param>
						</thx:pages>
					</div>
				</div>
				<form id="user-form" name="ui-adminlte-form" class="form-horizontal"
						data-toggle="validator" role="form" method="post"
						container = "div.right"
						action="${pageContext.request.contextPath}/information/comment!save.action"
						forward-action="${pageContext.request.contextPath}/information/information!view.action?pid=${view.information.infoId}">
						<s:token></s:token>
						<input type="hidden" name="id" value=""/>
						<input type="hidden" name="pid" value="${view.information.infoId}"/>
						<input type="hidden" name="message" value="${message}" />				
		                <div class="box-footer">
		                  <div class="input-group">
		                  		<input type="text" name="entity.content" id="commentcontent" class="form-control required" placeholder="发表评论...">
			                    <div class="input-group-btn">
			             			<button type="button" 
										title="评论" 
										class="btn btn-primary information-commentSaveBut" 
										data-id="${view.information.infoId}">
										<i class="fa fa-plus"></i>
									</button>
			                    </div>
		                  </div>
		                </div>
                </form>
              </div><!-- /.box (chat box) -->
            </div>
            </c:if>
            <!-- 结束评论显示区域 -->							
		</div>
	</div>
</section>
<script>
	require(['util','list', 'thx-page','dialog'], function(util,list,page,dialog) {
		list.init();
		page.init('div.right');
		var ctxPath = "${pageContext.request.contextPath}";
		// 返回栏目列表
		$(".information-columngoBut").click(
			function() {
				var data_id = $(this).attr("data-id");
				var href = ctxPath
						+ '/information/information!list.action?columnId='+data_id;
				util.ajaxPage(href,'',true,'div.right');
		});
		// 提交评论
		$(".information-commentSaveBut").click(
			function() {
				var commentcontent = $("#commentcontent").val();
				if(commentcontent==null || commentcontent==""){
					dialog.alert("评论内容必填");
				}else{
					var data_id = $(this).attr("data-id");
					var action = ctxPath+"/information/comment!save.action";
					var forwardAction = ctxPath+"/information/information!view.action?id="+data_id;
					var container = "div.right";
					var options = {
						url : action,
						data : $("#user-form").serialize(),
						type : 'post',
						success : function(msg) {
							msg = util.strToObj(msg);
							dialog.alert(msg.desc);
							if (msg.code == "success"&&forwardAction)
								//modify xjw 优化表单提交后页面跳转
								util.ajaxPage(forwardAction,'',false,container);
						},
						error : function() {
							dialog.alert("提交异常！");
						}
					};
					$.ajax(options);
				}
		});
		// 投票
		$(".information-joinVoteBut").click(
			function() {
				var data_id = $(this).attr("data-id");
				var itemForm = "${view.information.itemForm}";

				// 如果是单选,判断单选值由没有选中
				var selectVal = "";
				if(itemForm=="0"){
					if($("input[type='radio'][name='voteItemIds']:checked").length == 0){
						dialog.alert("请选择一个投票项");
					}else{
						// 调用投票函数
						vote(data_id);
					}
				}
				if(itemForm=="1"){
					if($("input[type='checkbox'][name='voteItemIds']:checked").length == 0){
						dialog.alert("请至少选择一个投票项");
					}else{
						// 调用投票函数
						vote(data_id);
					}
				}
		});

		function vote(data_id){
 			var action = ctxPath+"/information/vote!joinVote.action";
			var forwardAction = ctxPath+"/information/information!view.action?id="+data_id;
			var container = "div.right";
			var options = {
				url : action,
				data : $("#vote-form").serialize(),
				type : 'post',
				success : function(msg) {
					msg = util.strToObj(msg);
					dialog.alert(msg.desc);
					if (msg.code == "success"&&forwardAction)
						//modify xjw 优化表单提交后页面跳转
						util.ajaxPage(forwardAction,'',false,container);
				},
				error : function() {
					dialog.alert("提交异常！");
				}
			};
			$.ajax(options);
		};
	});
</script>

